#ifndef THINK_THINK_DB_CONNECTOR_SQLSRV_H
#define THINK_THINK_DB_CONNECTOR_SQLSRV_H

static char* think_db_connector_sqlsrv =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think\\db\\connector;\n"
	"\n"
	"use PDO;\n"
	"use think\\db\\Connection;\n"
	"\n"
	"/**\n"
	" * Sqlsrv数据库驱动\n"
	" */\n"
	"class Sqlsrv extends Connection\n"
	"{\n"
	"    // PDO连接参数\n"
	"    protected $params = [\n"
	"        PDO::ATTR_CASE              => PDO::CASE_NATURAL,\n"
	"        PDO::ATTR_ERRMODE           => PDO::ERRMODE_EXCEPTION,\n"
	"        PDO::ATTR_STRINGIFY_FETCHES => false,\n"
	"    ];\n"
	"    protected $builder = \'\\\\think\\\\db\\\\builder\\\\Sqlsrv\';\n"
	"    /**\n"
	"     * 解析pdo连接的dsn信息\n"
	"     * @access protected\n"
	"     * @param array $config 连接信息\n"
	"     * @return string\n"
	"     */\n"
	"    protected function parseDsn($config)\n"
	"    {\n"
	"        $dsn = \'sqlsrv:Database=\' . $config[\'database\'] . \';Server=\' . $config[\'hostname\'];\n"
	"        if (!empty($config[\'hostport\'])) {\n"
	"            $dsn .= \',\' . $config[\'hostport\'];\n"
	"        }\n"
	"        return $dsn;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 取得数据表的字段信息\n"
	"     * @access public\n"
	"     * @param string $tableName\n"
	"     * @return array\n"
	"     */\n"
	"    public function getFields($tableName)\n"
	"    {\n"
	"        list($tableName) = explode(\' \', $tableName);\n"
	"        $tableNames      = explode(\'.\', $tableName);\n"
	"        $tableName       = isset($tableNames[1]) ? $tableNames[1] : $tableNames[0];\n"
	"\n"
	"        $sql = \"SELECT   column_name,   data_type,   column_default,   is_nullable\n"
	"        FROM    information_schema.tables AS t\n"
	"        JOIN    information_schema.columns AS c\n"
	"        ON  t.table_catalog = c.table_catalog\n"
	"        AND t.table_schema  = c.table_schema\n"
	"        AND t.table_name    = c.table_name\n"
	"        WHERE   t.table_name = \'$tableName\'\";\n"
	"\n"
	"        $pdo    = $this->query($sql, [], false, true);\n"
	"        $result = $pdo->fetchAll(PDO::FETCH_ASSOC);\n"
	"        $info   = [];\n"
	"        if ($result) {\n"
	"            foreach ($result as $key => $val) {\n"
	"                $val                       = array_change_key_case($val);\n"
	"                $info[$val[\'column_name\']] = [\n"
	"                    \'name\'    => $val[\'column_name\'],\n"
	"                    \'type\'    => $val[\'data_type\'],\n"
	"                    \'notnull\' => (bool) (\'\' === $val[\'is_nullable\']), // not null is empty, null is yes\n"
	"                    \'default\' => $val[\'column_default\'],\n"
	"                    \'primary\' => false,\n"
	"                    \'autoinc\' => false,\n"
	"                ];\n"
	"            }\n"
	"        }\n"
	"        $sql = \"SELECT column_name FROM information_schema.key_column_usage WHERE table_name=\'$tableName\'\";\n"
	"        // 调试开始\n"
	"        $this->debug(true);\n"
	"        $pdo = $this->linkID->query($sql);\n"
	"        // 调试结束\n"
	"        $this->debug(false, $sql);\n"
	"        $result = $pdo->fetch(PDO::FETCH_ASSOC);\n"
	"        if ($result) {\n"
	"            $info[$result[\'column_name\']][\'primary\'] = true;\n"
	"        }\n"
	"        return $this->fieldCase($info);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 取得数据表的字段信息\n"
	"     * @access public\n"
	"     * @param string $dbName\n"
	"     * @return array\n"
	"     */\n"
	"    public function getTables($dbName = \'\')\n"
	"    {\n"
	"        $sql = \"SELECT TABLE_NAME\n"
	"            FROM INFORMATION_SCHEMA.TABLES\n"
	"            WHERE TABLE_TYPE = \'BASE TABLE\'\n"
	"            \";\n"
	"\n"
	"        $pdo    = $this->query($sql, [], false, true);\n"
	"        $result = $pdo->fetchAll(PDO::FETCH_ASSOC);\n"
	"        $info   = [];\n"
	"        foreach ($result as $key => $val) {\n"
	"            $info[$key] = current($val);\n"
	"        }\n"
	"        return $info;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * SQL性能分析\n"
	"     * @access protected\n"
	"     * @param string $sql\n"
	"     * @return array\n"
	"     */\n"
	"    protected function getExplain($sql)\n"
	"    {\n"
	"        return [];\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif